package org.jeecg.modules.system.controller.login;

import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.login.parameter.OriginalParameter;
import org.jeecg.common.message.UnicomSmsUtil;
import org.jeecg.common.util.RedisUtil;
import org.jeecg.modules.base.service.BaseCommonService;
import org.jeecg.modules.system.entity.SysUser;
import org.jeecg.modules.system.service.ISysDepartService;
import org.jeecg.modules.system.service.ISysDictService;
import org.jeecg.modules.system.service.ISysTenantService;
import org.jeecg.modules.system.service.ISysUserService;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * 账号密码登录
 *
 * @author jiangtianyi
 * @version 1.0.0
 */
@Slf4j
@RestController
@RequestMapping("/sys")
@ConditionalOnExpression("'${basicplatform.login.original.enable:true}'.equals('true')")
public class OriginalLoginHandler extends LoginHandler {

    /**
     * 账号密码登录
     *
     * @param originalParameter {@link OriginalParameter}
     * @author jiangtianyi
     * @since 1.0
     */
    @PostMapping("/login")
    public Result<?> login(@RequestBody @Valid OriginalParameter originalParameter) {
        Result<?> result = super.routineVerification(originalParameter);
        if (result.isSuccess()) {
            SysUser sysUser = (SysUser) result.getResult();
            return super.doLogin(sysUser);
        }
        return result;
    }

    public OriginalLoginHandler(RedisUtil redisUtil, UnicomSmsUtil unicomSmsUtil, RsaEncryptProperty rsaEncryptProperty, BaseCommonService baseCommonService, ISysDictService sysDictService, ISysTenantService sysTenantService, ISysUserService sysUserService, ISysDepartService sysDepartService, RedisTemplate<String, Object> redisTemplate) {
        super(redisUtil, unicomSmsUtil, rsaEncryptProperty, baseCommonService, sysDictService, sysTenantService, sysUserService, sysDepartService, redisTemplate);
    }

}